package com.mumuso.mumusoitem.controller;

import com.mumuso.mumusoitem.pojo.dArcStaff;
import com.mumuso.mumusoitem.service.dArcStaffService;
import com.mumuso.mumusoitem.utils.AjaxResult;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import static com.mumuso.mumusoitem.utils.ParseUrl.getUrl;

@RestController
@RequestMapping("/staff")
public class dArcStaffController {

    @Autowired
    private dArcStaffService dArcStaffService;


    /**
     * 根据staffID获取制单人信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/selectStaInfoByStaId/")
    public AjaxResult selecyStaInfoByStaffId(HttpServletRequest request) {
        String queryString = request.getQueryString();
        String staffID = getUrl(queryString, "StaffID");

        if (StringUtils.isBlank(staffID)) {
            return AjaxResult.error("未被定义的参数!!!!");
        }

        try {
            // 获取到制单对象
            dArcStaff staffInfo = dArcStaffService.getStaffInfoByStaId(staffID);
            //判断是否为空
            if (ObjectUtils.isNotEmpty(staffInfo)) {
                return AjaxResult.success(staffInfo);
            } else {
                return AjaxResult.error("为获取到该制单人信息!!!!!");
            }
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }
}
